<?php
class BaseDao
{
	protected $db;
	
	public function __construct($table)
	{
		$this->db = new LtDb($table);
	}
	
	public function get($id)
	{
		$tmp	= $this->db->get($id);
		if(!$tmp)
		{
			return false;
		}
		
		return $tmp;
	}
	
	public function add($data)
	{
		if(!array_key_exists('created', $data))
		{
			$data['created']	= date('Y-m-d H:i:s');
		}
		$result = $this->db->insert($data);
		return $result;
	}
	
	public function update($id,$data)
	{
		return $this->updateRows(array('where'=>array('id'=>$id)), $data);
	}
	
	public function updateRows($con, $data)
	{
		return $this->db->updateRows($con, $data);
	}
	
	public function del($id)
	{
		return $this->db->delete($id);
	}
	
	public function count($con)
	{
		return $this->db->count($con);
	}
	
	public function fetch($con)
	{
		return $this->db->fetch('',$con);
	}
	
	public function fetchRows($con,$orderby='',$fields='',$start=0,$num=0)
	{
		return $this->db->fetchRows($fields, $con, '', $orderby, $num, $start);
	}
	
	public function deleteRows($con)
	{
		return $this->db->deleteRows($con);
	}
}